package com.ruoyi.web.controller.applets;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.dto.IndexItemDto;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.IFileService;
import com.ruoyi.system.service.ISysDictTypeService;
import com.ruoyi.task.domain.Task;
import io.swagger.models.auth.In;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 小程序首页Controller
 *
 * @author KevenPotter
 * @date 2024-05-20 16:56:20
 */
@RestController
@RequestMapping("/applets/index")
@AllArgsConstructor
public class AppletsIndexController extends BaseController {

    private final ISysDictTypeService dictTypeService;
    private final IFileService fileService;


    /**
     * 查询类目列表
     *
     * @return 返回类目列表
     * @author KevenPotter
     * @date 2024-04-30 09:41:20
     */
    @Anonymous
    @GetMapping("/listItem")
    public AjaxResult list() {
        List<SysDictData> sysDictDataList = dictTypeService.selectDictDataByType("sys_item");
        List<IndexItemDto> itemDtoList = new ArrayList<>();
        sysDictDataList.forEach(item -> {
            IndexItemDto indexItemDto = new IndexItemDto();
            indexItemDto.setId(Integer.valueOf(item.getDictValue())).setName(item.getDictLabel()).setIcon(fileService.buildSingleFileUrlFullPath(item.getRemark()));
            itemDtoList.add(indexItemDto);
        });
        return AjaxResult.success(itemDtoList);
    }
}
